package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.YhPointRecord;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YhPointsWithdrawalRules;
import com.ruoyi.system.service.IYhPointsWithdrawalRulesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分提现规则Controller
 * 
 * @author ruoyi
 * @date 2023-06-06
 */
@Api(tags = "积分提现规则管理")
@RestController
@RequestMapping("/yh/rules")
public class YhPointsWithdrawalRulesController extends BaseController
{
    @Autowired
    private IYhPointsWithdrawalRulesService yhPointsWithdrawalRulesService;


    /**
     * 获取积分提现规则详细信息
     */
    @ApiOperation("获取积分提现规则详细")
    @PreAuthorize("@ss.hasPermi('yh:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhPointsWithdrawalRules yhPointsWithdrawalRules)
    {
        startPage();
        List<YhPointsWithdrawalRules> list = yhPointsWithdrawalRulesService.list(yhPointsWithdrawalRules.queryWrapper());
        return getDataTable(list);
    }
    /**
     * 获取积分提现规则详细信息
     */
    @ApiOperation("获取积分提现规则详细")
    @PreAuthorize("@ss.hasPermi('yh:rules:list')")
    @GetMapping()
    public AjaxResult getInfo()
    {
        return success(yhPointsWithdrawalRulesService.getById(1));
    }


    /**
     * 修改积分提现规则
     */
    @ApiOperation("更新积分提现规则")
    @PreAuthorize("@ss.hasPermi('yh:rules:edit')")
    @Log(title = "积分提现规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhPointsWithdrawalRules yhPointsWithdrawalRules)
    {
        if (StringUtils.isNull(yhPointsWithdrawalRules.getWithdrawalRatio())) {
            throw new ServiceException("请填写积分兑换比例！");
        }
        YhPointsWithdrawalRules pointsWithdrawalRules = new YhPointsWithdrawalRules();
        pointsWithdrawalRules.setId("1");
        pointsWithdrawalRules.setWithdrawalRatio(yhPointsWithdrawalRules.getWithdrawalRatio());
        return toAjax(yhPointsWithdrawalRulesService.updateById(pointsWithdrawalRules));
    }

}
